/* $Id: ErrorMessage.java,v 1.3 2005/02/11 17:53:09 gigabass Exp $
*
* Copyright (c) Guido Ludwig. All rights reserved.
* Use is subject to license terms.
*/

package de.guidoludwig.af;

import javax.swing.JOptionPane;

/**
 * Handle error messages / exceptions
 * 
 * @author <a href="mailto:jtrade@gigabss.de">Guido Ludwig</a>
 * @version $Revision: 1.3 $
 */
public class ErrorMessage {
    public static final void handle(Throwable e, String message) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, message + "\n" + stackTrace(e),
            "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }

    public static final void handle(Throwable e) {
        handle("Error", e);
    }
    
    public static final void handle(String message, Throwable e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, stackTrace(e), message,
            JOptionPane.ERROR_MESSAGE);
    }    

    public static final void message(String message) {
        JOptionPane.showMessageDialog(null, message, "Error",
            JOptionPane.ERROR_MESSAGE);
        return;
    }

    private static final String stackTrace(Throwable e) {
        StringBuffer sb = new StringBuffer(e.getMessage() + "\n");
        Object[] lines = e.getStackTrace();
        for (int i = 0; i < lines.length; i++) {
            sb.append(lines[i] + "\n");
        }
        return sb.toString();
    }

    private ErrorMessage() {
    }
}